<template>
  <!--推荐的上架商品-->
  <div class="recom">
    <div class="categoryName">我的收藏</div>
    <div class="goodsList">
      <ul>
        <li v-for="(collect, index) in pageInfo.list" :key="index" @click="toGoodsView(collect.goods.id)">
          <div class="pic">
            <el-image
                :src="`${SERVER_ADDR}/goods/pic/${collect.goods.picList[0].url}`"
                style="width: 225px; height: 150px"
            />
          </div>
          <div class="name">{{ collect.goods.name }}</div>
          <div class="dscp">{{ collect.goods.dscp}}</div>
          <div class="price">￥ {{collect.goods.price}}</div>
        </li>
      </ul>
    </div>
  </div>
  <div class="collectNav">
    <el-row justify="center">
      <el-pagination background layout="prev, pager, next"
                     :page-count="pageInfo.pages"
                     @update:current-page="selectByUser"
                     style="margin-top: 10px; text-align: center"
                     v-model:current-page="pageInfo.pageNum" />
    </el-row>

  </div>
</template>

<script setup>
import collectApi from "@/api/collectApi.js";
import {ref} from "vue";
import {useRouter} from "vue-router";

//服务器的地址
const SERVER_ADDR = ref(import.meta.env.VITE_SERVER_ADDR)
const pageInfo = ref({});
const router = useRouter();
const getUserCollects = (pageNum) => {
  collectApi.select(pageNum,5 )
      .then(resp => {
        if (resp.code == 10000) {
          pageInfo.value = resp.data;
        }
      })
}
//跳转到商品详情页面
const toGoodsView = (id)=>{
  router.push({
    path: '/user/goods',
    query: {
      id
    }
  });

}
getUserCollects(1);
</script>

<style scoped>
.ad {
  margin: 20px 0;
}
.ad ul li {
  float: left;
  width: 285px;
  margin-right: 20px;
}
.ad ul li:last-child{
  margin-right: 0px;
}
.recom .goodsList ul li {
  width: 224px;
  float: left;
  margin-right: 20px;
  margin-bottom: 15px;
  text-align: center;
  background-color: #fff;
  cursor: pointer;
}
.recom .goodsList ul li:hover{
  box-shadow: 0px 0px 20px #000;
}
.recom .goodsList ul li:nth-child(5n) {
  margin-right: 0px;
}

.recom {
  margin-bottom: 20px;
}

.recom .categoryName {
  font-size: 20px;
  margin-bottom: 5px;
  font-weight: bold;
}
.name, .dscp, .price{
  line-height: 25px;
}
.recom .name {
  font-size: 16px;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recom .dscp {
  color: #aaa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recom .price {
  font-size: 12px;
  color:  var(--theme-color);
}
.collectNav {
  padding: 10px;
  background-color: #ffffff;
}
</style>